package com.ye.controller;

import com.ye.domain.Music;
import com.ye.domain.R;
import com.ye.service.MusicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RefreshScope
@RequestMapping("/music")
public class MusicController {

    @Autowired
    private MusicService musicService;

    @GetMapping("/getMusicListByName")
    public R getMusicListByName(String songName) {
        List<Music> musicListByName = musicService.getMusicListByName(songName);
        return R.ok(musicListByName).count(musicListByName.size());
    }

    @GetMapping("/fuzzySearchMusic")
    public R fuzzySearch(@RequestParam("songName") String songName) {
        List<Music> music = musicService.fuzzySearch(songName);
        return R.ok(music).count(music.size());
    }

    @GetMapping("/countMusic")
    public R countMusicNum(){
        Integer musicNum = musicService.countMusicNum();
        return R.ok(musicNum);
    }

    //    随机12首歌曲
    @GetMapping("/randMusic")
    public R rand12(){
        List<Music> musicList = musicService.rand12();
        return R.ok(musicList).count(musicList.size());
    }

}
